package com.example.jdcompetition.Controller;

import com.example.jdcompetition.Entity.CallResultMsg;
import com.example.jdcompetition.Entity.CodeAndMsg;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author henrydai
 * @date 2021/6/16 20:36
 */
@RestControllerAdvice(annotations = RestController.class)
public class UniformReponseHandler<T> {

    @ResponseStatus(HttpStatus.OK)
    public CallResultMsg sendSuccessResponse(T data) {
        return new CallResultMsg(true, CodeAndMsg.SUCCESS, data);
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CallResultMsg collectFileFailed(T data)
    {
        return new CallResultMsg(false,CodeAndMsg.COLLECTEXCEPTION1,data);
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CallResultMsg transitFileFailed(T data)
    {
        return new CallResultMsg(false,CodeAndMsg.TRANSITEXCEPTION1,data);
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CallResultMsg deliverFileFailed(T data)
    {
        return new CallResultMsg(false,CodeAndMsg.DELIVEREXCEPTION1,data);
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CallResultMsg collectComputeFailed(T data)
    {
        return new CallResultMsg(false,CodeAndMsg.COLLECTEXCEPTION2,data);
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CallResultMsg transitComputeFailed(T data)
    {
        return new CallResultMsg(false,CodeAndMsg.TRANSITEXCEPTION2,data);
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CallResultMsg deliverComputeFailed(T data)
    {
        return new CallResultMsg(false,CodeAndMsg.DELIVEREXCEPTION2,data);
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CallResultMsg unkownException(T data)
    {
        return new CallResultMsg(false,CodeAndMsg.UNKNOWNEXCEPTION,data);
    }
}